package hczc.longcai.com.hccrowdfunding.home.second_invest.activities;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.security.Key;
import java.util.ArrayList;
import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.activity.BaseActivity;
import hczc.longcai.com.hccrowdfunding.home.second_invest.adapters.ProjectCommentAdapter;
import hczc.longcai.com.hccrowdfunding.home.second_invest.beans.ProjectComment;

public class ProjectCommentActivity extends BaseActivity implements View.OnClickListener, View.OnTouchListener {

    private static final String TAG = "ProjectCommentActivity";
    private View back;
    private TextView title;
    private ListView listView;
    private List<ProjectComment> list;
    private ProjectCommentAdapter adapter;
    private EditText comment;

    private ImageView like;
    private ImageView dislike;

    private boolean isLike;

    View.OnKeyListener listener = new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                ((EditText) v).setText("");
                sendComment();
                if (imm.isActive()) {
                    imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
                }
                return true;
            }
            return false;
        }
    };



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project_comment);

        initDatas();
        initViews();

    }

    private void sendComment() {
//        Log.d(TAG,"************************************");
    }

    private void initDatas() {
        list = new ArrayList<>();
        list.add(new ProjectComment());
        list.add(new ProjectComment());
        list.add(new ProjectComment());
    }

    private void initViews() {
        back = findViewById(R.id.head_back);
        back.setOnClickListener(this);
        back.setOnTouchListener(this);
        title = ((TextView) findViewById(R.id.head_title));
        title.setText("项目评论");
        findViewById(R.id.head_right_pic).setVisibility(View.GONE);

        comment = ((EditText) findViewById(R.id.invest_project_comment_comment));
        comment.setOnKeyListener(listener);

        like = ((ImageView) findViewById(R.id.invest_project_comment_like));
        dislike = ((ImageView) findViewById(R.id.invest_project_comment_dislike));


        listView = ((ListView) findViewById(R.id.invest_project_comment_listview));
        adapter = new ProjectCommentAdapter(this, list);
        listView.setAdapter(adapter);
    }


    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {

            case R.id.head_back:
                finish();
                break;

        }
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        view.setPressed(true);
        return false;
    }
}
